package com.df.hitime.common;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * @description: 随机生成四位邀请码工具类
 * @author: tigerlin
 * @createtime: 2018/11/26 17:05
 */
public class RandomUtil {

    public static String getCode(Integer length) {
//        String str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String str = "0123456789";
        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            char ch = str.charAt(new Random().nextInt(str.length()));
            sb.append(ch);
        }
        return sb.toString();
    }

    //生成订单号 yymmddhhmmss+3为随机数+5报名表主键（5位不够补0）
    public static String createOrderSn(Integer resourceId){
        SimpleDateFormat df = new SimpleDateFormat("yyMMddHHmmss");
        String orderSn=df.format(new Date())+getCode(3)+String.format("%05d", resourceId);
        return orderSn;
    }

    //获取uuid 并去掉横线
    public static String getUUID(){
        String uuid=UUID.randomUUID().toString();
        uuid = uuid.replace("-", "");
        return uuid;
    }
}
